<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false"
    :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="rules" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()"
      label-width="120px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="反馈类型 " >
            {{ dataForm.contentTypeName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="内容">
            {{ dataForm.content }}
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="上传的资料">
           <div class=" display-flex">
              <div v-for="item in xdfdtrt(dataForm.imgUrl)">
                  <img :src="item" class="kjxzczxftrtrt">
              </div>
           </div>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="归属企业">
            {{ dataForm.companyName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="真实姓名">
            {{ dataForm.realName }}
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系电话">
            {{ dataForm.userPhone }}
          </el-form-item>
        </el-col>
      </el-row>






      <!-- <el-form-item label="反馈类型" prop="contentType">
        <el-input v-model="dataForm.contentType" placeholder="反馈类型"></el-input>
      </el-form-item>
         
          <el-form-item label="资料id" prop="imgId">
        <el-input v-model="dataForm.imgId" placeholder="资料id"></el-input>
      </el-form-item>
     
          <el-form-item label="排序" prop="sort">
        <el-input v-model="dataForm.sort" placeholder="排序"></el-input>
      </el-form-item>  -->
      <el-form-item label="审核" prop="isPass">

        <el-radio-group v-model="dataForm.isPass">
          <el-radio :label="1">待处理</el-radio>
          <el-radio :label="2">已结案</el-radio>
          <!-- <el-radio :label="3">3审核不通过</el-radio> -->
        </el-radio-group>

      </el-form-item>
      <!-- <el-form-item label="审核不通过内容" prop="passContent">
        <el-input v-model="dataForm.passContent" placeholder="审核不通过内容"></el-input>
      </el-form-item> -->
      <!-- <el-form-item label="创建时间" prop="createTime">
        <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
      </el-form-item>
          <el-form-item label="更新时间" prop="updateTime">
        <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>
      </el-form-item>
          <el-form-item label="企业id" prop="companyId">
        <el-input v-model="dataForm.companyId" placeholder="企业id"></el-input>
      </el-form-item>
          <el-form-item label="归属企业" prop="companyName">
        <el-input v-model="dataForm.companyName" placeholder="归属企业"></el-input>
      </el-form-item>
          <el-form-item label="真实姓名" prop="realName">
        <el-input v-model="dataForm.realName" placeholder="真实姓名"></el-input>
      </el-form-item>
          <el-form-item label="联系电话" prop="userPhone">
        <el-input v-model="dataForm.userPhone" placeholder="联系电话"></el-input>
      </el-form-item> -->
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">确定</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts" setup>
import { reactive, ref } from "vue";
import baseService from "@/service/baseService";
import { ElMessage } from "element-plus";
const emit = defineEmits(["refreshDataList"]);

const visible = ref(false);
const dataFormRef = ref();

const dataForm = reactive({
  id: '', userId: '', type: '', contentDicCode: '', contentType: '', content: '', imgId: '', imgUrl: '', sort: '', isPass: '', passContent: '', createTime: '', updateTime: '', companyId: '', companyName: '', realName: '', userPhone: ''
});

const rules = ref({
  userId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  type: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  contentDicCode: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  contentType: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  content: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  imgId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  imgUrl: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  sort: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  isPass: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  passContent: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  createTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  updateTime: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  companyId: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  companyName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  realName: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ],
  userPhone: [
    { required: true, message: '必填项不能为空', trigger: 'blur' }
  ]
});

const init = (id?: number) => {
  visible.value = true;
  dataForm.id = "";

  // 重置表单数据
  if (dataFormRef.value) {
    dataFormRef.value.resetFields();
  }

  if (id) {
    getInfo(id);
  }
};

// 获取信息
const getInfo = (id: number) => {
  baseService.get("/api/userdata/" + id).then((res) => {
    Object.assign(dataForm, res.data);
  });
};

// 表单提交
const dataFormSubmitHandle = () => {
  dataFormRef.value.validate((valid: boolean) => {
    dataForm.contentType = 5
    if (!valid) {
      return false;
    }
    (!dataForm.id ? baseService.post : baseService.put)("/api/userdata", dataForm).then((res) => {
      ElMessage.success({
        message: '成功',
        duration: 500,
        onClose: () => {
          visible.value = false;
          emit("refreshDataList");
        }
      });
    });
  });
};

defineExpose({
  init
});
const xdfdtrt = (data)=>{
 try{
  return data.split(",")
 }catch(e){

 }
}
</script>
<style scoped>
  .kjxzczxftrtrt{
    width: 100px;
    height: 100px;
    margin-right: 10px;
  }
</style>